package com.fzrskj.cloud.free.user.service;

import com.fzrskj.cloud.free.user.utils.agent.UserAgentUtils;
import ms.core.consts.SysErr;
import ms.core.object.CObject;
import ms.core.tool.JsonTool;
import ms.core.tool.XmlCodeParser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * UserAgentService.
 *
 * @author zj.
 *         Created on 2019/8/14 0014.
 */
public class UserAgentService extends CObject {
    /**
     * 代理设置.
     */
    public String setAgentInfo (HttpServletRequest req, HttpServletResponse resp, String p, String sid){
        Integer userId = JsonTool.getIntValue(p, "userId", 0);
        String isAgent = JsonTool.getStrValue(p, "isAgent", "");
        if (userId < 1 || (!"Y".equals(isAgent) && !"N".equals(isAgent) )) {
            return XmlCodeParser.formatCustomTips(false, SysErr.SYS_PARAM_ERR);
        }

        UserAgentUtils agentUtils = new UserAgentUtils();
        Boolean flag = agentUtils.modify(userId, isAgent);
        if (!flag) {
            return XmlCodeParser.formatCustomTips(false, agentUtils.getErrCode(), agentUtils.getMsg());
        }
        return XmlCodeParser.formatCustomTips(true, SysErr.CODE_SUCCESS);
    }

}
